
# ifndef __DFX_SINGLETON_H__
# define __DFX_SINGLETON_H__

# include "dfxCore.h"

namespace DFX
{
    template <class T> class Singleton
    {
    protected:

        static T *msSingleton;

    public:

        Singleton()
        {
            msSingleton = static_cast<T*>(this);
        }

        static T* GetPtr()
        {
            return msSingleton;
        }

        static T& Get()
        {
            return *msSingleton;
        }

        static void SetPtr(T *singleton)
        {
            msSingleton = singleton;
        }

        static void Set(T &singleton)
        {
            msSingleton = &singleton;
        }
    };

    template <class T> T* Singleton<T>::msSingleton = NULL;
}

# endif